package is.ejs.bahamut;

import java.security.SecureRandom;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class DiceRollActivity extends Activity {
	SecureRandom generator = new SecureRandom();

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dicerolllayout);

	}

	public void diceRollCalculate(View view) {
		TextView singlesView = (TextView) findViewById(R.id.diceRollSingle);
		TextView sumView = (TextView) findViewById(R.id.diceRollSum);
		EditText typeText = (EditText) findViewById(R.id.diceRollTypeEdit);
		EditText numberText = (EditText) findViewById(R.id.diceRollNumberEdit);
		String typeString = typeText.getText().toString();
		String numberString = numberText.getText().toString();
		int typeInt = Integer.parseInt(typeString);
		int numberInt = Integer.parseInt(numberString);
		String singlesString = "singles: ";
		int sumInt = 0;
		String randomString;
		sumView.setText("");
		singlesView.setText("");

		for (int i = 0; i < numberInt; i++) {
			int randomInt = generator.nextInt(typeInt);
			randomInt += 1;
			sumInt += randomInt;
			randomString = Integer.toString(randomInt);
			singlesString += randomString + ", ";
		}

		String sumString = "sum: " + Integer.toString(sumInt);
		sumView.setText(sumString);
		singlesView.setText(singlesString);

	}
}
